package com.work.ygj.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.work.ygj.common.model.Response;
import com.work.ygj.common.model.page.PageResult;
import com.work.ygj.entity.Notice;
import com.work.ygj.pojo.dto.NoticeDto;
import com.work.ygj.pojo.vo.NoticeVo;
import com.work.ygj.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import com.work.ygj.controller.BaseController;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  系统通知管理(管理员)(用户只能看列表)
 *
 * @author ygj
 * @since 2022-03-27
 */
@Controller
@RequestMapping("/notice")
@ResponseBody
public class NoticeController extends BaseController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 系统通知列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<PageResult<NoticeVo>> selectList(@RequestBody NoticeDto dto){
        return Response.success(getDataTable(noticeService.selectList(dto)));
    }

    /**
     * 新增系统通知信息
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody Notice req) {
        noticeService.save(req);
        return Response.success();
    }


    /**
     * 修改系统通知信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody Notice req) {
        UpdateWrapper<Notice> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        noticeService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除系统通知记录
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody Notice req) {
        Notice entity = new Notice();
        entity.setId(req.getId());
        entity.setDeleted("1");
        noticeService.updateById(entity);
        return Response.success();
    }

    /**
     * 系统通知信息详情
     *
     * @param req
     * @return
     */
    @PostMapping("/detail")
    public Response<Notice> detail(@RequestBody Notice req) {
        Notice entity = noticeService.getById(req.getId());
        return Response.success(entity);
    }
}

